package com.study.rocket.base.producer;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.util.concurrent.TimeUnit;

/**
 * @author mjy(发送单向消息)
 * @date 2021/12/10
 * @description
 */
public class OneWayProducer {


    public static void main(String[] args) throws Exception {
        //创建一个消息生产者
        DefaultMQProducer producer = new DefaultMQProducer("group1");
        //指定nameService地址
        producer.setNamesrvAddr("127.0.0.1:9876");
        //启动消费者
        producer.start();
        for (int i = 0; i < 10; i++) {
            //创建消息对象，指定主题Topic、tag和消息体
            /**
             * 参数一：消息主题topic
             * 参数二：消息tag
             * 参数内容
             */
            Message message = new Message("base", "tag3", ("hellow word" + i).getBytes());
            TimeUnit.SECONDS.sleep(1);
            //发送单向的消息
            producer.sendOneway(message);
        }
        producer.shutdown();

    }
}
